package com.ruoyi.project.poem.poemset.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.poem.poemset.domain.PoemSet;
import com.ruoyi.project.poem.poemset.service.IPoemSetService;
import com.ruoyi.project.poem.poemsetdetail.service.IPoemSetDetailService;

/**
 * 诗词诗单Controller
 * 
 * @author shixiangwen
 * @date 2020-03-30
 */
@Controller
@RequestMapping("/poem/poemset")
public class PoemSetController extends BaseController {

	private String prefix = "poem/poemset";

	@Autowired
	private IPoemSetService poemSetService;

	@Autowired
	IPoemSetDetailService poemSetDetailService;

	@RequiresPermissions("poem:poemset:view")
	@GetMapping()
	public String poemset() {
		return prefix + "/poemset";
	}

	/**
	 * 查询诗词诗单列表
	 */
	@RequiresPermissions("poem:poemset:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PoemSet poemSet) {
		startPage();
		List<PoemSet> list = poemSetService.selectPoemSetList(poemSet);
		return getDataTable(list);
	}

	/**
	 * 导出诗词诗单列表
	 */
	@RequiresPermissions("poem:poemset:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(PoemSet poemSet) {
		List<PoemSet> list = poemSetService.selectPoemSetList(poemSet);
		ExcelUtil<PoemSet> util = new ExcelUtil<PoemSet>(PoemSet.class);
		return util.exportExcel(list, "poemset");
	}

	/**
	 * 新增诗词诗单
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存诗词诗单
	 */
	@RequiresPermissions("poem:poemset:add")
	@Log(title = "诗词诗单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PoemSet poemSet) {
		return toAjax(poemSetService.insertPoemSet(poemSet));
	}

	/**
	 * 修改诗词诗单
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		PoemSet poemSet = poemSetService.selectPoemSetById(id);
		mmap.put("poemSet", poemSet);
		return prefix + "/edit";
	}

	/**
	 * 修改保存诗词诗单
	 */
	@RequiresPermissions("poem:poemset:edit")
	@Log(title = "诗词诗单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PoemSet poemSet) {
		return toAjax(poemSetService.updatePoemSet(poemSet));
	}

	/**
	 * 删除诗词诗单
	 */
	@RequiresPermissions("poem:poemset:remove")
	@Log(title = "诗词诗单", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(poemSetService.deletePoemSetByIds(ids));
	}
}
